<?php
 
class Link_model extends CI_Model {
	var $page;
	var $name;
	var $is_editable;
	
	static $links = null;

	public static function get_link($id) {
		self::initialize_links();
		return self::$links[$id];
	}
	public static function get_link_by_page($page) {
		Link_model::initialize_links();
		foreach (self::$links as $link) {
			if ($link->page == $page) {
				return $link;
			}
		}
		return null;
	}
	private static function initialize_links() {
		if (!isset(self::$links)) {
			self::$links = array();
			$link_model = new Link_model();
			foreach ($link_model->select_all() as $link) {
				self::$links[$link->id] = $link;
			}
		}
	}

	function __construct() {
		parent::__construct();
		$this->load->database();
	}

	function select_all() {
		return $this->db->get('links')->result();
	}
}
